local skel = fk.CreateSkill {
  name = "kpaI__fulang",
}

Fk:loadTranslationTable{
  ["kpaI__fulang"] = "抚浪",
  [":kpaI__fulang"] = "当你造成或受到伤害后，你可令当前回合角色本回合只能再使用你已损失体力值张牌，本回合结束时，你可使用剩余次数张牌以回复1点体力。",

  ["#kpaI__fulang"] = "卷涡：你可令当前回合角色本回合只能再使用%arg张牌，本回合结束时，你可使用剩余次数张牌以回复1点体力。",
  ["#kpaI__fulang_ask"] = "你可以使用使用%arg张牌以回复1点体力。",

  ["@kpaI__fulang-turn"] = "抚浪",
  ["@@kpaI__fulangend-turn"] = "抚浪：禁用牌",
  ["@kpaI__fulanguse-turn"] = "抚浪：剩余可用牌数",
}

local can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player
  end
local on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = skel.name,
      prompt = "#kpaI__fulang:::"..player:getLostHp(),
    }) then
      return true
    end
  end
local on_use = function (self, event, target, player, data)
    local room = player.room
    local n = player:getLostHp()
    local to = room:getCurrent()
    room:setPlayerMark(to,"@kpaI__fulang-turn",n)
  end

skel:addEffect(fk.Damage, {
  can_trigger = can_trigger,
  on_cost = on_cost,
  on_use = on_use,
})

skel:addEffect(fk.Damaged, {
  can_trigger = can_trigger,
  on_cost = on_cost,
  on_use = on_use,
})

skel:addEffect(fk.TurnEnd,{
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target:getMark("@kpaI__fulang-turn") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"@kpaI__fulanguse-turn",target:getMark("@kpaI__fulang-turn"))
    room:setPlayerMark(target,"@kpaI__fulang-turn",0)
    while player:getMark("@kpaI__fulanguse-turn") > 0 do
      local use = room:askToUseCard(player,{
        prompt = "#kpaI__fulang_ask:::" .. player:getMark("@kpaI__fulanguse-turn"),
        pattern = ".",
        skill_name = skel.name,
      })
      if use then
        room:useCard(use)
        room:setPlayerMark(player,"@kpaI__fulanguse-turn",player:getMark("@kpaI__fulanguse-turn")-1)
        if player:getMark("@kpaI__fulanguse-turn") == 0 then
          room:recover({
            who = player,
            num = 1,
            skillName = skel.name,
          })
          return
        end
      else
        return
      end
    end
  end,
})

skel:addEffect(fk.CardUsing,{
  can_refresh = function (self, event, target, player, data)
    return player:getMark("@kpaI__fulang-turn") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if player:getMark("@kpaI__fulang-turn") == 1 then
      room:setPlayerMark(player,"@@kpaI__fulangend-turn",1)
    end
    room:setPlayerMark(player,"@kpaI__fulang-turn",player:getMark("@kpaI__fulang-turn")-1)
  end,
})

skel:addEffect("prohibit", {
  prohibit_use = function(self, player)
    return player:getMark("@@kpaI__fulangend-turn") > 0
  end,
})


return skel
